<template>
  <div class="app-container">
    账号:(国内用户请输入手机号)
    <el-input v-model="dynamicValidateForm.account" placeholder="请输入账号"></el-input>
    密码:
    <el-input v-model="dynamicValidateForm.password" placeholder="请输入密码" type="password"></el-input>
    确认密码:
    <el-input v-model="dynamicValidateForm.repassword" placeholder="请重复输入密码" type="password"></el-input>
    <el-button type="primary" @click="savefrom">确 定</el-button>
  </div>
</template>

<script>
  import {register} from '@/api/Service'
  import md5 from 'md5'

  export default {
    name: "register",
    data() {
      return {
        activeName2: 'first',
        dynamicValidateForm: {
          account: '',
          password: '',
          repassword: '',
        }
      }
    },
    methods: {
      savefrom() {
        if (this.isvalidUsername(this.dynamicValidateForm.account) && this.dynamicValidateForm.repassword == this.dynamicValidateForm.password) {
          register({
            repassword: md5(this.dynamicValidateForm.repassword),
            password: md5(this.dynamicValidateForm.password),
            account: btoa(this.dynamicValidateForm.account)
          }).then(response => {
            console.log()
            if (response.data.status == 200) {
              this.dynamicValidateForm.repassword = ''
              this.dynamicValidateForm.password = ''
              this.dynamicValidateForm.account = ''
              alert('注册成功!')
            } else {
              alert(response.data.msg)
            }
          })
        } else {
          alert('请输入正确的账号,以及密码')
        }
      },
      isvalidUsername(str) {
        const email = /^([A-Za-z0-9_\-\.\u4e00-\u9fa5])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,8})$/
        const tel = /^1[3-9](\d{9})$/
        return (email.test(str) || tel.test(str))
      }
    }
  }
</script>

<style scoped>

</style>
